Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push down version filter in the Delta $history table #16192

Conversation

findinpath
Copy link
Contributor

Description

Doing the pushdown for the version column predicates helps out in avoiding to load unnecessary transaction log files from the storage.

As part of the changes done for this feature, the Delta $history table avoids materializing all the entries of the table at once by using the same strategy as #16112

Additional context and related issues

SELECT * FROM "test_table$history" WHERE version > 218;

Release notes

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Feb 20, 2023
@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch 2 times, most recently from f0edb4a to 78ef37c Compare February 21, 2023 12:38
@krvikash krvikash self-requested a review February 21, 2023 13:42
@findinpath findinpath marked this pull request as draft February 21, 2023 23:03
@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch from 78ef37c to f24e14d Compare February 21, 2023 23:29
@findinpath findinpath marked this pull request as ready for review February 21, 2023 23:30
@findinpath findinpath self-assigned this Feb 21, 2023
@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch 5 times, most recently from 88b453b to cf835ab Compare February 22, 2023 15:06
{
requireNonNull(startVersion, "identity is null");
requireNonNull(endVersion, "identity is null");
verify(startVersion.orElse(0L) <= endVersion.orElse(startVersion.orElse(0L)), "startVersion is greater than endVersion");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a duplicate code from DeltaLakeTransactionLogEntryIterator? we can extract into a method verifyVersion?

@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch 4 times, most recently from 0323ce7 to 389fe6c Compare February 26, 2023 08:39
@findinpath
Copy link
Contributor Author

Rebase on top of master to deal with conflicting files.

@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch from 389fe6c to bbfbbed Compare February 27, 2023 06:35
@findinpath findinpath requested a review from krvikash February 27, 2023 06:37
@homar
Copy link
Member

homar commented Feb 28, 2023

do you need those .crc files? Wouldn't all the tests work without them ?

@findinpath
Copy link
Contributor Author

do you need those .crc files? Wouldn't all the tests work without them ?

@homar no the files are not needed for the tests to run successfully. I copied the content of the table as it was from Databricks. I see a mixture in the test resources of _delta_log directories with and without .crc files. I don't feel strongly about keeping/removing those files. If you insist, we can have them removed.

@homar
Copy link
Member

homar commented Feb 28, 2023

do you need those .crc files? Wouldn't all the tests work without them ?

@homar no the files are not needed for the tests to run successfully. I copied the content of the table as it was from Databricks. I see a mixture in the test resources of _delta_log directories with and without .crc files. I don't feel strongly about keeping/removing those files. If you insist, we can have them removed.

I don't have strong opinion. I just don't think we need them so maybe it would be better not to have unnecessary files. But you don't have to remove them if you don't agree

1 similar comment
@homar
Copy link
Member

homar commented Feb 28, 2023

do you need those .crc files? Wouldn't all the tests work without them ?

@homar no the files are not needed for the tests to run successfully. I copied the content of the table as it was from Databricks. I see a mixture in the test resources of _delta_log directories with and without .crc files. I don't feel strongly about keeping/removing those files. If you insist, we can have them removed.

I don't have strong opinion. I just don't think we need them so maybe it would be better not to have unnecessary files. But you don't have to remove them if you don't agree

@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch from bbfbbed to 9bfc116 Compare February 28, 2023 19:26
@github-actions github-actions bot added the delta-lake Delta Lake connector label Feb 28, 2023
@findinpath
Copy link
Contributor Author

Rebasing on master to deal with code conflicts.

@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch from 9bfc116 to 49d11bd Compare March 7, 2023 10:53
Copy link
Member

@alexjo2144 alexjo2144 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First two commits only

Comment on lines 100 to 133
stream(commitInfoEntries)
.map(commitInfoEntry -> getRecord(commitInfoEntry, timeZoneKey))
.iterator();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than going back and forth to Stream you can just use Iterables.transform or Iterators.transform

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did change to Iterables.transform in the 1st commit.
However, in the 2nd commit, I find the stream approach more straightforward to read. I don't see how to get to a similar result without Streams.stream method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're just looking for Iterators.concat? To replace the Stream flatMap

import static java.util.Objects.requireNonNull;

public class DeltaLakeTransactionLogIterator
implements Iterator<List<DeltaLakeTransactionLogEntry>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a flat Iterator<DeltaLakeTransactionLogEntry>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flat iterator comes with increased overhead. I created initially such an iterator, but it has rather high complexity for little gain - the transaction log file is read at once.

See draft implementation
https://github.com/trinodb/trino/compare/f0edb4afb7f92815526e121acffbef19382a9558..78ef37c36721b29952f052fb7da9f1a5bb847bb9

Comment on lines +85 to +87
if (stopped) {
return Optional.empty();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopped seems unnecessary to me, but maybe I'm missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without stopped we could call hasNext() several times and this would incur further unnecessary reads in case when the endVersion is not present. Same thing for the situation when a transaction log in between - e.g. 1,2,3,5,6 - note that 4 is missing - is missing.

Comment on lines +134 to +135
"00000000000000000006.json", 17,
"_last_checkpoint", 17));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a sense of why these two are so high on these queries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I counted while debugging 9 times the call to io.trino.connector.system.SystemTablesMetadata#checkAndGetTable while performing a SELECT from the $history system metadata table.

Each of this calls eventually causes a subsequent DeltaLakeMetadata#getTableHandle() call which calls TransactionLogParser#tryReadLastCheckpoint.

I was planning to create an issue to further investigate whether we could spare some getTableHandle() calls.

@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch from 49d11bd to 903b2e3 Compare March 7, 2023 20:41
@findinpath findinpath requested a review from alexjo2144 March 7, 2023 20:41
fileSystem,
new Path(metastore.getTableLocation(tableName, session)),
Optional.empty(),
Optional.empty()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these 4 lines be more indented ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found a better way to highlight the stream. Could you pls suggest a change in this regard?

@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch from 903b2e3 to 1119dd8 Compare March 9, 2023 06:51
@findinpath findinpath force-pushed the findinpath/delta-history-table-version-pushdown branch from 1119dd8 to 0760302 Compare March 9, 2023 06:53
@findinpath
Copy link
Contributor Author

CI hit #15187

@findinpath
Copy link
Contributor Author

Superseded by #18427

@findinpath findinpath closed this Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed delta-lake Delta Lake connector
Development

Successfully merging this pull request may close these issues.

4 participants